// JavaScript Document
$().ready(function() {
	var resetEvenColor = function(){
		$('tbody tr').removeClass("alt-row");
		$('tbody tr:even').delay(100).addClass("alt-row");	
	};
	$("tbody td").buttonset();
	$("input[type=radio]").click(function(e){
		var tmp =  $(this);
		$.post("/action/master/AdsActive", { Action: "post", id:tmp.val() },
					function (data, textStatus){
						//$("#errormsg").text(data.message);
						if (!data.success) {
							//$(".notification").removeClass("success").addClass("error").fadeTo("slow", 1).fadeIn(400).delay(4000).slideUp(400);
							$(".loadingbox").empty();
							$(".loadingbox").append(loadingTpl , {
							   icoType: 'fail',
							   loadIcon: '',
							   msgHtml: data.message
							});
							$(".loadingbox").delay(3000).fadeOut(600);
						}else{
							$("#tr_"+tmp.val()).effect("highlight", {color:"#FF0"}, 3000 );
							$(".loadingbox").empty();
							$(".loadingbox").append(loadingTpl , {
							   icoType: "succ",
							   loadIcon: "",
							   msgHtml:data.message
							});
							$(".loadingbox").fadeIn(50);
							$(".loadingbox").delay(2000).fadeOut(600);
							//$(".notification").removeClass("error").addClass("success").fadeTo("slow", 1).fadeIn(400).delay(4000).slideUp(400);
						}
					}, "json");
	});
	
	
	$(".deleteBtn").click(function(e){
		var tmp =  $(e.currentTarget);
			$.post("/action/master/deleteAds", { Action: "post", id:tmp.attr("href") },
					function (data, textStatus){
						//$("#errormsg").text(data.message);
						if (!data.success) {
							$(".loadingbox").empty();
							$(".loadingbox").append(loadingTpl , {
							   icoType: 'fail',
							   loadIcon: '',
							   msgHtml: data.message
							});
							$(".loadingbox").delay(3000).fadeOut(600);
							//$(".notification").removeClass("success").addClass("error").fadeTo("slow", 1).fadeIn(400).delay(4000).slideUp(400);
						}else{
							$(".loadingbox").empty();
							$(".loadingbox").append(loadingTpl , {
							   icoType: "succ",
							   loadIcon: "",
							   msgHtml:data.message
							});
							$(".loadingbox").fadeIn(50);
							$(".loadingbox").delay(2000).fadeOut(600);
							//tmp.parents('tr').remove();
							tmp.parents('tr').effect("highlight", {color:"#F00"}, 800, function(){
								$(this).remove();
								resetEvenColor();
							});
							//$(".notification").removeClass("error").addClass("success").fadeTo("slow", 1).fadeIn(400).delay(4000).slideUp(400);
						}
					}, "json");
			return false;
	}).easyconfirm({locale: {title: '操作确认',text:'您确定要删除该广告么？', button: ['取消','是的，确定删除']}});
});